// pages/order/order.js
var app = getApp();
var req = require("../../utils/req.js");
var url = require("../../utils/url.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeIndex: '',
    current_page: 0,
    orderList: [],
    state:''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getOrderList();
  },
  /**
   * 得到订单明细的数据
   */
  getOrderList: function () {
    var that = this;
    var data = {
      page: that.data.current_page
    }
    req.userRequest("请稍等", 'POST', url.user['queryUserSpend'], data, function back(res) {
      // console,log(res)
      var data = res.data;

      if (that.data.orderList.length == 0 && data.length == 0) {
        wx.showToast({
          icon: 'none',
          title: '暂无订单明细',
        })
      }

      //判断数据是否为null
      if (data.length!=0) {
        //合并数组
        that.data.orderList.push.apply(that.data.orderList, data);
        // that.data.activeIndex.push.apply(that.data.activeIndex,data.state)
        that.setData({
          orderList: that.data.orderList,
          // activeIndex: that.data.activeIndex
        })
      }else{
        wx.showToast({
          icon: 'none',
          title: '已经到底了！',
        })
      }
    });
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log('fresh');
    var that = this;
    this.getProList(() => {
      that.data.isLoadedAll = false;
      wx.stopPullDownRefresh();
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.isLoadedAll) {
      this.data.current_page++;
      this.getOrderList();
    }
  },
})